﻿@using System.ComponentModel

<Table DataSource="@data" Bordered Size="TableSize.Small" ScrollX="1350" ScrollY="600">
    <ColumnDefinitions>
        <ColumnDefinition Width="100" Fixed="ColumnFixPlacement.Left" />
        <ColumnDefinition Width="200" />
        <ColumnDefinition Width="200" />
        <ColumnDefinition Width="200" />
        <ColumnDefinition Width="200" />
        <ColumnDefinition />
        <ColumnDefinition Width="80" Fixed="ColumnFixPlacement.Right" />
    </ColumnDefinitions>
    <HeaderTemplate>
        <TableRow>
            <SimpleTableHeader RowSpan="2">Avatar</SimpleTableHeader>
            <TableHeader @bind-Field="context.Name" Filters="filters" OnFilter="(v1, v2) => v2.Contains(v1)" />
            <TableHeader @bind-Field="context.Age" Sortable />
            <SimpleTableHeader>Street</SimpleTableHeader>
            <SimpleTableHeader>Building</SimpleTableHeader>
            <SimpleTableHeader>Door No.</SimpleTableHeader>
            <SimpleTableHeader RowSpan="2">Gender</SimpleTableHeader>
        </TableRow>
        <TableRow>
            <SimpleTableHeader ColSpan="2">Company Name</SimpleTableHeader>
            <SimpleTableHeader ColSpan="3">Company Address</SimpleTableHeader>
        </TableRow>
    </HeaderTemplate>
    <RowTemplate>
        <TableRow>
            <TableCell RowSpan="2"><Avatar Size="@("64")" Icon="@IconType.Outline.User" /></TableCell>
            <TableCell>@context.Data.Name</TableCell>
            <TableCell>@context.Data.Age</TableCell>
            <TableCell>@context.Data.Street</TableCell>
            <TableCell>@context.Data.Building</TableCell>
            <TableCell>@context.Data.Number</TableCell>
            <TableCell RowSpan="2">@context.Data.Gender</TableCell>
        </TableRow>
        <TableRow>
            <TableCell ColSpan="2">@context.Data.CompanyName</TableCell>
            <TableCell ColSpan="3">@context.Data.CompanyAddress</TableCell>
        </TableRow>
    </RowTemplate>
</Table>

@code{
    Data[] data;

    TableFilter<string>[] filters;

    public class Data
    {
        public int Key { get; set; }

        public string Name { get; set; }

        public int Age { get; set; }

        public string Street { get; set; }

        public string Building { get; set; }

        public int Number { get; set; }

        public string CompanyAddress { get; set; }

        public string CompanyName { get; set; }

        public string Gender { get; set; }
    }

    protected override void OnInitialized()
    {
        data = Enumerable.Range(0, 100).Select(x => new Data
        {
            Key = x,
            Name = "John Brown",
            Age = x + 1,
            Street = "Lake Park",
            Building = "C",
            Number = 2035,
            CompanyAddress = "Lake Street 42",
            CompanyName = "SoftLake Co",
            Gender = "M",
        }).ToArray();

        filters = new TableFilter<string>[]
        {
            new TableFilter<string>
            {
                Text = "Joe", 
                Value = "Joe"
            },
            new TableFilter<string>
            {
                Text = "John", 
                Value = "John"
            },
        };
    }
}